﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace SkyBase
{
    class Line: GameObject
    {
        public Rectangle line;
        public Color lineColor;

        public Line(String nameIn, Texture2D spriteIn, bool collidableIn, World worldIn, float priority = 0.5f) :
            base(nameIn, Vector2.Zero, spriteIn, collidableIn, worldIn, priority = 0.5f)
        {
            //Debugger.enabled = true;
            lineColor = Color.White;
        }


        public override void Draw(SpriteBatch spriteBatch)
        {
            Vector2 playerLoc = new Vector2(World.objects["player"].Location.X + 16, World.objects["player"].Location.Y + 16);
            Vector2 length = playerLoc - new Vector2((Mouse.GetState().X + -World.GetEngine().GetCameraPos().X), (Mouse.GetState().Y + -World.GetEngine().GetCameraPos().Y));
            line.Width = (int)length.Length();
            line.Height = 10;
            line.Location = new Point((int)playerLoc.X, (int)playerLoc.Y);
            this.Location = new Vector2(line.Location.X, line.Location.Y);
            //this.Bounds = line;
            Vector2 slope = new Vector2((Mouse.GetState().X + -World.GetEngine().GetCameraPos().X) - playerLoc.X, (Mouse.GetState().Y + -World.GetEngine().GetCameraPos().Y) - playerLoc.Y);
            rotation = slope.Y / slope.X;
            rotation = Math.Atan(rotation);
            if ((slope.Y > 0 && slope.X < 0) || (slope.Y < 0 && slope.X < 0))
                rotation += Math.PI;

            spriteBatch.Draw(Storage.getTexture("line"), line, null, lineColor, (float)rotation, new Vector2(0, 0), SpriteEffects.None, 0);
        }

        public override void onCollision(GameObject collidee)
        {
            if (collidee.Name.ToLower().Contains("wall"))
            {
                lineColor = Color.Red;
                Debugger.writeLine("LINE ONCOLLISION");
            }
        }

        public override Rectangle Bounds
        {
            get { return line; }
        }
    }
}
